package com.feri.ssm.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
/**
 * @author Feri
 * @date 2021/12/14 10:59
 * @description:TODO
 */
//@Aspect
public class QuerySqlTime {

    //前置通知
//    @Before("切入点表达式")
//    @After()
//    @AfterReturning
//    @AfterThrowing
//    @Around(value = "")
    public void before(JoinPoint point){
        System.err.println("前置通知："+point.getSignature().getName());
    }
    //后置通知
    public void after(JoinPoint point,Object r){
        System.err.println("后置通知："+point.getSignature().getName());
    }
    //异常通知
    public void exception(JoinPoint point,Throwable throwable){
        System.err.println("异常通知，出毛病");
    }

    //环绕通知
    public Object round(ProceedingJoinPoint point){
        try {
            long l=System.currentTimeMillis();
            //执行原来的方法，务必执行
            Object r=point.proceed();
            System.err.println("执行时间："+(System.currentTimeMillis()-l));
            return r;
        } catch (Throwable e) {
            e.printStackTrace();
            if(e instanceof RuntimeException){
                //回滚
            }else{
                //提交
            }
            return null;
        }
    }
}
